//
//  LGTeamRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/17.
//

#import "LGTeamRecordCell.h"
#import "DCAvatar.h"
@interface LGTeamRecordCell()
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIButton *refuseBtn;
/**   */
@property (nonatomic , strong)UIButton *agreeBtn;

@end

@implementation LGTeamRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
//    [self.headPic sd_setImageWithURL:[NSURL URLWithString:dataDic[@"avatar"]] placeholderImage:defaultDoctorPic];
    [self.headPic dc_setImageAvatarWithGroupId:LGNSString(dataDic[@"teamid"]) Source:dataDic[@"avatar"]];
    if([dataDic[@"title2"] length]>0){
        self.nameLabel.text = dataDic[@"title1"];
        self.contentLabel.text = dataDic[@"title2"];
        [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView).offset(viewPix(10));
        }];
    }else{
        self.nameLabel.text = @"";
        self.contentLabel.text = dataDic[@"title1"];
        [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
        }];
    }
    self.statusLabel.text = dataDic[@"checkstatus"];
    NSString *colorStr = [dataDic[@"checkstatus"] isEqualToString:@"等待验证"]?@"#333333":@"#CCCCCC";
    self.statusLabel.textColor = [UIColor colorWithString:colorStr];
    if([dataDic[@"needchecked"] integerValue] == 1){
        self.refuseBtn.hidden = NO;
        self.agreeBtn.hidden = NO;
        self.statusLabel.hidden = YES;
    }else{
        self.refuseBtn.hidden = YES;
        self.agreeBtn.hidden = YES;
        self.statusLabel.hidden = NO;
    }
}

-(void)refuseBtnAction{
    if(self.checkApplyAction){
        self.checkApplyAction(LGNSString(self.dataDic[@"teamid"]),LGNSString(self.dataDic[@"userid"]), @"2");
    }
}


-(void)agreeBtnAction{
    if(self.checkApplyAction){
        self.checkApplyAction(LGNSString(self.dataDic[@"teamid"]),LGNSString(self.dataDic[@"userid"]), @"1");
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.headPic];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.refuseBtn];
    [self.contentView addSubview:self.agreeBtn];
    [self.contentView addSubview:self.lineView];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nameLabel);
        make.centerY.equalTo(self.contentView).offset(viewPix(10));
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.agreeBtn.mas_left).offset(-viewPix(8));
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(viewPix(45)));
        make.height.equalTo(@(viewPix(26)));
    }];
    
    [self.agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.centerY.width.height.equalTo(self.refuseBtn);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic);
        make.right.equalTo(self.agreeBtn);
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}
-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(8), viewPix(42), viewPix(42))];
        _headPic.backgroundColor = [UIColor colorWithString:@"#EEEEEE"];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(viewPix(66), viewPix(8), viewPix(170), viewPix(23));
    }
    return _nameLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#CCCCCC" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UIButton *)refuseBtn{
    if(!_refuseBtn){
        _refuseBtn = [UIButton buttonWithTitle:@"拒绝" titleFont:LGFont(14) textColor:@"#429BFF" imageName:@""];
        _refuseBtn.layer.borderColor = [UIColor colorWithString:@"#429BFF"].CGColor;
        _refuseBtn.layer.borderWidth = 1;
        _refuseBtn.cornerRidus = 5;
        [_refuseBtn addTarget:self action:@selector(refuseBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _refuseBtn;
}

-(UIButton *)agreeBtn{
    if(!_agreeBtn){
        _agreeBtn = [UIButton buttonWithTitle:@"同意" titleFont:LGFont(14) textColor:@"#FFFFFF" imageName:@""];
        _agreeBtn.backgroundColor = [UIColor colorWithString:@"#429BFF"];
        _agreeBtn.cornerRidus = 5;
        [_agreeBtn addTarget:self action:@selector(agreeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreeBtn;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E1E1E1"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
